﻿using System;
using System.Linq;

namespace BLL
{
    public class baseBLL
    {
        public static D Mapper<D, S>(S s, D d)
        {
            //D d = Activator.CreateInstance<D>(); //构造新实例
            try
            {
                var Types = s.GetType();//获得类型  
                var Typed = typeof(D);
                foreach (System.Reflection.PropertyInfo sp in Types.GetProperties())//获得类型的属性字段  
                {
                    foreach (System.Reflection.PropertyInfo dp in Typed.GetProperties())
                    {
                        if (dp.Name == sp.Name && dp.PropertyType == sp.PropertyType && dp.Name != "Error" && dp.Name != "Item")//判断属性名是否相同  
                        {
                            var val = sp.GetValue(s, null);
                            if (val != null) dp.SetValue(d, val, null);//获得s对象属性的值复制给d对象的属性  
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return d;
        }


    }

    public class Pager
    {
        public Pager(object datalist, int totalrecords, int pageindex, int pagesize = 10)
        {
            this.pageIndex = pageindex;
            this.totalRecords = totalrecords;
            this.dataList = datalist;
            this.pageSize = pagesize;
        }
        public int totalRecords { set; get; }
        public int pageIndex { set; get; }
        public int pageSize { set; get; }

        public object dataList { set; get; }
    }

}
